import request from "@/utils/request";



/**
 * base64转文件
 * @param data
 * @param fileName
 */
export const base64ConvertFile = (data:string, fileName:string) => {
    const dataArr = data.split(',')
    const byteString = atob(dataArr[1])
    const options = {
        type: 'image/jpeg',
        endings: 'native'
    }
    const u8Arr = new Uint8Array(byteString.length)
    for (let i = 0; i < byteString.length; i++) {
        u8Arr[i] = byteString.charCodeAt(i)
    }
    return new File([u8Arr], fileName + '.jpg', options)
}


export const uploadFile = (file:File) => {
    const formData = new FormData()
    formData.append('file',file)
    return request({
        url: '/file/upload',
        method: 'post',
        data: formData
    })
}
